package com.demo.common.base;

import com.demo.model.User;
import com.demo.model.UserInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;

/**
 * @Description: ResultModel
 * @Author: ChenXueLi
 * @Date: 2018-10-02 14:18
 */
@Data
public class ResultModel {

    @ApiModelProperty(value = "状态码", name = "code")
    private int code = 0;

    @ApiModelProperty(value = "返回信息", name = "message")
    private String message = "";

    @ApiModelProperty(value = "返回参数", name = "data")
    private Object data = null;

    @ApiModelProperty(value = "操作用户", name = "userInfo")
    private UserInfo userInfo = null;

    @ApiModelProperty(value = "当前页数", name = "page")
    private int page = 1;

    @ApiModelProperty(value = "默认每页显示", name = "rows")
    private int rows = 10;

    @ApiModelProperty(value = "服务器时间", name = "currentTime")
    private Date currentTime = new Date();

    /**
     * 操作成功
     */
    public void info() {
      this.info("保存成功");
    }

    /**
     * 操作成功
     */
    public void info(String message) {
        this.code = 0;
        this.message = message;
    }

    /**
     * 操作失败
     * @param code
     */
    public void error(int code) {
        this.error(code, "操作失败");
    }

    /**
     * 操作失败
     * @param code
     * @param message
     */
    public void error(int code, String message) {
        this.code = 0;
        this.message = message;
    }

}
